/**
 * hnjz.com Inc.
 * Copyright (c) 2004-2013 All Rights Reserved.
 */
package com.hnjz.common;

import java.util.List;
import java.util.Map;

import org.springframework.ui.ModelMap;

/**
 * 框架中返回json结果的工具类
 * 
 * @author wumi
 * @version $Id: JsonResultUtil.java, v 0.1 Jan 11, 2013 10:06:20 AM wumi Exp $
 */
public class JsonResultUtil {

    /**
     * 返回操作成功的json
     * 
     * @param model {@link }
     * @param msg 提示信息
     */
    public static void suncess(ModelMap model, String msg) {
        model.addAttribute("state", Boolean.TRUE);
        model.addAttribute("msg", msg);
    }

    /**
     * 返回操作失败的json
     * 
     * @param model {@link }
     * @param msg 提示信息
     */
    public static void fail(ModelMap model, String msg) {
        model.addAttribute("state", Boolean.FALSE);
        model.addAttribute("msg", msg);
    }

    /**
     * 返回操作成功的json
     * 
     * @param model {@link }
     * @param re 分页结果
     */
    public static void fyWeb(ModelMap model, FyWebResult re) {
        model.addAttribute("total", re.getTotal());
        model.addAttribute("pageSize", re.getPerPageNum());
        model.addAttribute("pageNumber", re.getPageNumber());
        model.addAttribute("rows", re.getRows());

    }

    /**
     * 返回操作成功的json
     * 
     * @param model {@link }
     * @param re 分页结果
     */
    public static void listWeb(ModelMap model, List<?> rows) {
        model.addAttribute("total", rows.size());
        model.addAttribute("rows", rows);
    }

    /**
     * 返回数据
     * 
     * @param model
     * @param str
     */
    public static void show(ModelMap model, Map<String, Object> map) {
        model.addAllAttributes(map);
    }
}
